﻿using System;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using LuckyFish.ToDo.Data.Model;
using LuckyFish.ToDo.ViewModels;

namespace LuckyFish.ToDo.Views;

public partial class WelcomeView : UserControl
{
    public WelcomeView()
    {
        InitializeComponent();
        TodoControl = this.FindControl<ContentControl>("TodoControl");
    }

    private void InitializeComponent()
    {
        AvaloniaXamlLoader.Load(this);
    }

    private void SelectionTapped(object? sender, RoutedEventArgs e)
    {
        TodoControl.IsVisible = true;
        if(Parent?.DataContext is not MainWindowViewModel model)return;
        if(sender is not Control control)return;
        if(control.DataContext is not ToDoModel todo)return;
        TodoControl.Content = model.TodoLoad(todo);
    }
}